//package cn.iocoder.yudao.module.system.core;
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.util.ObjectUtil;
//import cn.hutool.json.ObjectMapper;
//import cn.iocoder.yudao.framework.common.exception.ErrorCode;
//import cn.iocoder.yudao.framework.common.exception.ServiceException;
//import cn.iocoder.yudao.framework.common.pojo.CommonResult;
//import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
//import cn.iocoder.yudao.framework.security.core.LoginUser;
//import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
//import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
//import cn.iocoder.yudao.module.system.service.user.AdminUserService;
//import com.alibaba.fastjson.JSONObject;
//import jakarta.annotation.Resource;
//import jakarta.servlet.http.HttpServletRequest;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import java.lang.reflect.Field;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
//
///**
// * 定时任务
// */
//@Aspect
//@Component
//public class ErpOperationLogAspect {
//
//    @AfterReturning(pointcut = "@annotation(cn.iocoder.yudao.module.system.core.ErpOperationLog)", returning = "result")
//    public void logOperation(JoinPoint joinPoint, CommonResult result) {
//      /*  MethodSignature signature=(MethodSignature) joinPoint.getSignature();
//        String methodName=signature.getMethod().getName();
//        Object[] args=joinPoint.getArgs();
//
//        HttpServletRequest request=((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
//        Integer code=result.getCode();
//        if(!ObjectUtil.equal(code,0)){
//            return;
//        }
//        Long userId;
//        if(ObjectUtil.equal(methodName,"login")){
//        Object data = result.getData();
//        JSONObject dJson = new JSONObject();
//        BeanUtil.copyProperties(data, dJson);
//        userId=dJson.getLong("userId");
//        }else{
//        userId=Objects.requireNonNull(SecurityFrameworkUtils.getLoginUser()).getId();
//        }
//        ErpOperationLog annotation = signature.getMethod().getAnnotation(ErpOperationLog.class);
//        String clientPublicIP=HttpUtils.getClientPublicIP(request);
//        String description="";
//        String module="";
//        if(annotation!=null) {
//        description=annotation.description();
//        module=annotation.module();
//        }
//
//        System.err.println("ip:"+clientPublicIP+", description："+description+" ,:module"+module+" ,:userId"+userId);
//        description="数据: ";
//        for (Object arg : args) {
//            if (arg != null) {
//                for (Field field : arg.getClass().getDeclaredFields()) {
//                    ErpOperationField erpofAnnotation = field.getAnnotation(ErpOperationField.class);
//                    if (erpofAnnotation != null) {
//                        field.setAccessible(true);
//                        try {
//                            System.err.println("Field Name: " + field.getName() + ", Value: " + field.get(arg)+","+erpofAnnotation.name());
//                        } catch (IllegalAccessException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
//            }
//        }
//*/
//
//    }
//
//}
//
